#include <stdio.h>

#include <string>

#include "linker.h"
bool showLink = false;
int main(int argc, char* argv[]) {
  //vingen
  // for (int i = 0; i < argc; i++) {
  //   printf("arg: %s\n", argv[i]);
  // }
  Linker linker;
  string desFileName;
  int i = 1;
  while (true) {
    if (i >= argc) {
      break;
    }
    string arg = argv[i];
    //vingen
    // printf("argc:%d arg:%s find:%lu len:%lu\n", argc,arg.c_str(),arg.rfind(".o"), arg.length());
    if (arg.rfind(".o") != arg.length() - 2)  //是输出文件
    {
      desFileName = arg;
      // printf("outfile: %s\n", desFileName.c_str());
    }
      // printf("msg: %s link start.\n", arg.c_str());
    linker.addElf(arg.c_str());  //添加目标文件
      // printf("msg: %s link end.\n", arg.c_str());

    i++;
  }
  showLink = (argv[i + 1][0] == 'y');  //获取参数
  linker.link(desFileName.c_str());    //开始链接
  return 0;
}
